package xcfg

import (
	"github.com/spf13/viper"
	"os"
)

var config *viper.Viper

func init() {
	config = viper.New()
	wd, err := os.Getwd()
	if err != nil {
		panic(err)
	}

	config.AddConfigPath(wd)
	config.SetConfigName("app")
	config.SetConfigType("yml")

	if err := config.ReadInConfig(); err != nil {
		panic(err)
	}
}

// 配置读取 二次封装
func Get(key string) interface{} {
	return config.Get(key)
}

func GetString(key string) string {
	return config.GetString(key)
}
func GetStringSlice(key string) []string {
	return config.GetStringSlice(key)
}

func GetInt(key string) int {
	return config.GetInt(key)
}
